package com.raymond.client.thread;

import com.raymond.client.config.ThreadPoolConfig;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * 线程池
 *
 * @author :  raymond
 * @version :  V1.0
 * @date :  2021-08-08 11:39
 */
public enum ThreadPool {
    /**
     * 回调线程池
     */
    CALLBACK(new ThreadPoolConfig("callBack"));

    private ThreadPoolExecutor callBackThreadPool;

    ThreadPool(ThreadPoolConfig threadPollManager) {
        this.callBackThreadPool = new ThreadPoolExecutor(threadPollManager.getCorePoolSize(), threadPollManager.getMaximumPoolSize(),
                threadPollManager.getKeepAliveTime(), threadPollManager.getUnit(), threadPollManager.getWorkQueue(),
                threadPollManager.getThreadFactory(), threadPollManager.getHandler());
    }

    public ThreadPoolExecutor getCallBackThreadPool() {
        return callBackThreadPool;
    }

    public void execute(Runnable runnable) {
        callBackThreadPool.execute(runnable);
    }
}
